$(document).ready(function(){
	
	$("#deleteReply").click(
		function(){
			var selectedId=$("#gridTable").jqGrid("getGridParam","selrow");
			
			if(selectedId){
				var ids=new Array();
				var selectedIds = $("#gridTable").jqGrid("getGridParam", "selarrrow");
				for(var i=0;i<selectedIds.length;i++){
					var id=jQuery('#gridTable').jqGrid('getCell',selectedIds[i],'replyId');
					alert(id);
					ids.push(id);
				}
				ids=ids.toString();
				alert(ids);
			var params={"ids":ids};
			 $.ajax({
            type: "post",
           	url: "admin/reply!deleteReplyByReplyIds",
            data:params,
            dataType: "json",
            success: function(data){
			  $("#gridTable").jqGrid('setGridParam',{url:"admin/reply!replyComments"}).trigger("reloadGrid");
               if (data == 1) {
                    alert("删除成功！");
               }
               else {
                   alert("删除失败！");
               }
                return true;
            },
            error: function(data){
				$("#gridTable").jqGrid('setGridParam',{url:"admin/reply!replyComments"}).trigger("reloadGrid");
                return false;
            }
        });
			}else{
				alert("请选择要删除的行！");
			}
		}
	);
	/**********配置jqgrid**********/
	   $("#gridTable").jqGrid({
        url: 'admin/reply!replyComments',
        datatype: "json",
        height: 350,
        colNames: ['编号','用户名','评论内容','发布日期'],
        colModel: [{
            name:'replyId',
            index:'replyId',
            width: 50,
            sorttype: "int",
            editable: true
        },
		{
			name:'tbUser.userName',
			index:'tbUser.userName',
			width:120,
		},
		{
			name:"content",
			index:'content',
			width:710,
		},{
			name:'replyTime',
			index:'replyTime',
			width:120,
		}],
        sortname: 'replyId',
        sortorder: 'desc',
        viewrecords: true,
        rowNum: 10,
        rowList: [10, 20, 30],
        jsonReader: {
            root: "replyList", // 数据行（默认为：rows）   
            page: "page", // 当前页   
            total: "totalPage", // 总页数   
            records: "totalCount", // 总记录数   
            repeatitems: false // 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设   
        },
		prmNames : {
			search : "search"
		},
        pager: "#gridPager",
        emptyrecords: "没有数据显示",
        multiselect: true,
        caption: "评论列表"
    });
    
    jQuery("#gridTable").jqGrid('navGrid', '#gridPager', {
        edit: true,
        add: true,
        del: false,
		search:true,
		position:"left"
    });
	
	
	
});

function queryReply(){
	var sdata = {   //构建查询需要的参数  
        content: $("#searchReply").val()    
    };    
    //获得当前postData选项的值  
    var postData = $("#gridTable").jqGrid("getGridParam", "postData");  
      
    //将查询参数融入postData选项对象  
    $.extend(postData, sdata);  
      
    $("#gridTable").jqGrid("setGridParam", {  
        search: true,mtype : "post"    // 将jqGrid的search选项设为true  
    }).trigger("reloadGrid", [{page:1}]);   //重新载入Grid表格，以使上述设置生效   
}
